﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace app1_mycalculator
{
    public class NumpadListener
    {
        private TextBox textBox;

        public NumpadListener(TextBox textBox)
        {
            this.textBox = textBox;
            this.textBox.KeyDown += new KeyEventHandler(textBox_KeyDown);
        }

        private void textBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9)
            {
                // 数字键盘输入
                int num = e.KeyCode - Keys.D0;
                textBox.Text += num.ToString();
            }
            else if (e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9)
            {
                // 数字键盘输入
                int num = e.KeyCode - Keys.NumPad0;
                textBox.Text += num.ToString();
            }
        }
    }
}
